﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Text;
using System.Data;

namespace ATW.MT.BUS
{
    public class bus_T_Concern
    {
        DataAccess da = null;
        public bus_T_Concern()
        {
            da = new DataAccess();
        }

        public DataTable ConcernPagerQuery(string LoginName, string TargetName, string Type, string pstart, string pend, int page, int pagesize)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(@"select t1.ConcernID,t1.targetID,t1.tauloginid,
                        (case 
		                when t1.type=1 then '联系'
		                when t1.type=2 then '关怀'
		                end) as Type,t1.create_time,u1.tauName loginName,u2.tauName targetName
                        from T_Concern t1 
                        left join T_AppUser u1 on t1.tauLoginId=u1.tauLoginId
                        left join T_AppUser u2 on t1.targetID=u2.tauLoginId
                        where 1=1");
            if (!String.IsNullOrEmpty(LoginName))
            {
                sql.Append(" and u1.tauName like '%" + LoginName + "%'");
            }
            if (!String.IsNullOrEmpty(TargetName))
            {
                sql.Append(" and u2.tauName like '%" + TargetName + "%'");
            }

            if (!String.IsNullOrEmpty(Type))
            {
                sql.Append(" and t1.type ='" + Type + "'");
            }
            if (!String.IsNullOrEmpty(pstart))
            {
                sql.Append(" and t1.create_time>cast('" + pstart + " 00:00:00' as datetime)");
            }
            if (!String.IsNullOrEmpty(pend))
            {
                sql.Append(" and t1.create_time<cast('" + pend + " 23:59:59' as datetime)");
            }

            return da.PageSize(sql.ToString(), page, pagesize, "ConcernID");
        }
    }
}